package com.woniuxy.web;

import com.woniuxy.entity.User;
import com.woniuxy.service.DishService;
import com.woniuxy.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * @author zhang
 * @create 2021-08-11-20:30
 */
@Controller

public class IndexController {
    @Autowired
    private DishService dishService;
    @Autowired
    private ShopService shopService;
    //进首页
    @GetMapping({"front/index","index","","/"})
    public String toIndex(HttpSession session,Model model){
        //user
        User user = (User) session.getAttribute("user");
        //将查询到的菜品数据存到模板中
        model.addAttribute("dishes",dishService.list());
        model.addAttribute("shops",shopService.list());
        session.setAttribute("user", user);
        return "index";
    }
    //进关于我们页面
    @GetMapping("aboutUs")
    public String goAboutUs(){
        return "article_read";
    }
}
